﻿@page "/index"
@page "/home"
@page "/"

@inject IConfiguration _configuration
@using Microsoft.Extensions.Logging
@using Microsoft.Extensions.Hosting

@inject IHostApplicationLifetime _applicationLifetime
@inject ISensitiveWordService _sensitiveWordService

<MCard Class="mb-4">
    <MCardText Class="pb-0">
        <MAlert Color="primary" Class="mb-0"
                Shaped
                Outlined
                 Icon="@("mdi-information")">
             请在根目录下的 <strong>appsettings.json</strong> 文件内编辑配置，部分配置将在重启后生效
         </MAlert>
     </MCardText>
     <MCardText>
         <dl>
             <div>
                 <dt>Swagger 文档</dt>
                 <dd><a href="/swagger">/swagger</a></dd>
             </div>
             <div>
                 <dt>敏感词总数</dt>
                 <dd>@_sensitiveWordService.Count()</dd>
            </div>
            @{
                var model = _configuration.AsEnumerable().ToList();
            }
            @foreach (var item in _selfConfigurations)
            {

                if (!model.Any(s => s.Key == item.Item1))
                {
                    continue;
                }
                var info = model.Find(s => s.Key == item.Item1);
                <div>
                    <dt>@($"{item.Item2} ( {item.Item1} )")</dt>
                    <dd>@(item.Item3 ? info.Value.ReplaceWithSpecialChar() : info.Value)</dd>
                </div>
            }
        </dl>
    </MCardText>
    <MCardActions>
        <MSpacer />
        <MButton Color="error" OnClick="Reboot">
            <MIcon Left Dark>
                mdi-refresh
            </MIcon>
            重新启动
        </MButton>
    </MCardActions>
</MCard>
<CnGalWebSite.RobotClientX.Components.Home.EditCard ConfigurationChanged="ConfigurationChanged" />

@code {


    private List<(string, string, bool)> _selfConfigurations = new List<(string, string, bool)>
{
            ("QQ","账号",false),
            ("RobotName","称呼",false),
            ("WarningQQGroup","接收预警的QQ群",false),
            ("MiraiUrl","Mirai IP",false),
            ("NormalVerifyKey","Mirai 验证密匙",true),
            ("ChannelToken","QQ频道 Token",true),
            ("ChannelAppKey","QQ频道 AppKey",true),
            ("ChatGPTModel","GPT模型",false),
            ("ChatGPTLimit","GPT对话上限每分钟",false),
            ("ChatGPTApiUrl","GPT API",false),
            ("ChatGPTApiKey","GPT Key",true),
            ("ChatGPT_SystemMessageTemplate","GPT 提示词",false),
            ("ChatGPT_UserMessageTemplate","GPT 消息模板",false),
            ("WebApiPath","CnGal资料站 API",false),
            ("WebSiteName","网站名称",false),
            ("WebSiteImage","网站背景图",false),
            ("WebSiteTheme","网站主题颜色",false),
             ("EventBus_HostName","RabbitMQ 主机名",false),
              ("EventBus_Port","RabbitMQ 端口",false),
               ("EventBus_UserName","RabbitMQ 用户名",false),
                ("EventBus_Password","RabbitMQ 密码",true),
        };

    public void Reboot()
    {
        _applicationLifetime.StopApplication();
    }

    public void ConfigurationChanged()
    {
        StateHasChanged();
    }
}
